<?php
class xl_comment{
    function read(){
        global $dbh;
        $sql='SELECT * FROM connected ORDER BY id DESC';
        $sth=$dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll();
    }
    function read_id($id){
        global $dbh;
        $sql='SELECT * FROM connected WHERE id=:id LIMIT 0,1';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return  $sth->fetch(PDO::FETCH_ASSOC);
    }
    function delete_all($id){
        global $dbh;
        $sql='SELECT * FROM connected WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function delete($id){
        global $dbh;
        $sql='DELETE FROM connected WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth;
    }
    function update_status($id){
        global $dbh;
        $sql='UPDATE connected SET status=1-status WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth;
    }
}